package com.jl.jlapp.popu;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.jl.jlapp.R;

public class ModifyNumPopu
        extends PopupWindow {
    EditText buyNum;
    TextView cancelBtn;
    CardView cardView;
    TextView okBtn;
    OnClickOkBtn onClickOkBtn;
    TextView tvAdd;
    private TextView tvKnow;
    TextView tvReduce;
    private View view;

    public ModifyNumPopu(final Context paramContext, final Integer paramInteger1, String paramString, final Integer paramInteger2, final Integer paramInteger3) {
        super(paramContext);
        this.view = ((LayoutInflater) paramContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.modify_num_popu, null);
        this.cardView = ((CardView) this.view.findViewById(R.id.layout));
        this.cancelBtn = ((TextView) this.view.findViewById(R.id.modify_num_bottom_cancel_btn));
        this.cancelBtn.setVisibility(View.VISIBLE);
        this.okBtn = ((TextView) this.view.findViewById(R.id.modify_num_bottom_ok_btn));
        this.buyNum = ((EditText) this.view.findViewById(R.id.tv_buy_num));
        this.tvReduce = ((TextView) this.view.findViewById(R.id.tv_reduce));
        this.tvAdd = ((TextView) this.view.findViewById(R.id.tv_add));
        this.buyNum.setText(paramString);
        if (Integer.parseInt(paramString) <= 1) {
            this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
        }
        this.okBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                if (!"".equals(ModifyNumPopu.this.buyNum.getText().toString().trim())) {
                    if (ModifyNumPopu.this.onClickOkBtn != null) {
                        ModifyNumPopu.this.onClickOkBtn.OnClickOkBtn(ModifyNumPopu.this.buyNum.getText().toString().trim());
                    }
                    return;
                }
                Toast.makeText(paramContext, "请输入购买数量", Toast.LENGTH_SHORT).show();
            }
        });
        this.tvReduce.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                Log.d("aaamodifity", "我执行了减");
                if (!"".equals(ModifyNumPopu.this.buyNum.getText().toString().trim())) {
                    int i = Integer.parseInt(ModifyNumPopu.this.buyNum.getText().toString().trim());
                    if (i <= 1) {
                        Toast.makeText(paramContext, "不能再减少了!", Toast.LENGTH_SHORT).show();
                        ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    }
                    do {
                        ModifyNumPopu.this.buyNum.setText(i - 1 + "");
                        if (i - 1 == 1) {
                            ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                        }
                    } while ((i - 1 >= 500) || (i - 1 >= paramInteger1.intValue()));
                    ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    return;
                }
                Toast.makeText(paramContext, "请输入购买数量", Toast.LENGTH_SHORT).show();
            }
        });
        this.tvAdd.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                Log.d("aaamodifity", "我执行了加");
                if (!"".equals(ModifyNumPopu.this.buyNum.getText().toString().trim())) {
                    int i = Integer.parseInt(ModifyNumPopu.this.buyNum.getText().toString().trim());
                    if ((paramInteger2.intValue() == 0) && (paramInteger3.intValue() == 2)) {
                        if (i < paramInteger1.intValue()) {
                            ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                            if (i < 500) {
                                ModifyNumPopu.this.buyNum.setText(i + 1 + "");
                                if (i + 1 == 500) {
                                    ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                                    return;
                                }
                                ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                                return;
                            }
                            ModifyNumPopu.this.buyNum.setText("500");
                            ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                            return;
                        }
                        Toast.makeText(paramContext, "库存上限为" + paramInteger1, Toast.LENGTH_SHORT).show();
                        ModifyNumPopu.this.buyNum.setText(paramInteger1 + "");
                        ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                        return;
                    }
                    ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    if (i < 500) {
                        ModifyNumPopu.this.buyNum.setText(i + 1 + "");
                        if (i + 1 == 500) {
                            ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                            return;
                        }
                        ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                        return;
                    }
                    ModifyNumPopu.this.buyNum.setText("500");
                    ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    return;
                }
                Toast.makeText(paramContext, "请输入购买数量", Toast.LENGTH_SHORT).show();
            }
        });
        this.buyNum.setInputType(3);
        this.buyNum.setInputType(2);
        this.buyNum.addTextChangedListener(new TextWatcher() {
            public void afterTextChanged(Editable paramAnonymousEditable) {
                int i;
                if (!"".equals(ModifyNumPopu.this.buyNum.getText().toString().trim())) {
                    int j = Integer.parseInt(ModifyNumPopu.this.buyNum.getText().toString().trim());
                    i = j;
                    if (j <= 0) {
                        ModifyNumPopu.this.buyNum.setText("1");
                        i = 1;
                        ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    }
                    if (i > 1) {
                        ModifyNumPopu.this.tvReduce.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                    }
                    if ((paramInteger2.intValue() != 0) || (paramInteger3.intValue() != 2)) {
                      return;
                    }
                    if (i > paramInteger1.intValue()) {
                        return;
                    }
                    if (i > 500) {
                        ModifyNumPopu.this.buyNum.setText("500");
                        ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    }
                } else {
                    return;
                }
                ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
                Toast.makeText(paramContext, "库存上限为" + paramInteger1, Toast.LENGTH_SHORT).show();
                ModifyNumPopu.this.buyNum.setText(paramInteger1 + "");
                ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                if (i > 500) {
                    ModifyNumPopu.this.buyNum.setText("500");
                    ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.moreText));
                    return;
                }
                ModifyNumPopu.this.tvAdd.setTextColor(paramContext.getResources().getColor(R.color.trans_333333));
            }

            public void beforeTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            }

            public void onTextChanged(CharSequence paramAnonymousCharSequence, int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3) {
            }
        });
        setContentView(this.view);
        setWidth(-1);
        setHeight(-1);
        setFocusable(true);
        setAnimationStyle(R.style.AnimBottom);
        setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(paramContext,R.color.white)));
        this.cancelBtn.setOnClickListener(new OnClickListener() {
            public void onClick(View paramAnonymousView) {
                ModifyNumPopu.this.dismiss();
            }
        });
        this.view.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View paramAnonymousView, MotionEvent paramAnonymousMotionEvent) {
                int i = ModifyNumPopu.this.cardView.getTop();
                int j = ModifyNumPopu.this.cardView.getLeft();
                int k = ModifyNumPopu.this.cardView.getWidth();
                int m = ModifyNumPopu.this.cardView.getHeight();
                int n = (int) paramAnonymousMotionEvent.getY();
                int i1 = (int) paramAnonymousMotionEvent.getX();
                if ((paramAnonymousMotionEvent.getAction() == 1) && ((n < i) || (i1 < j) || (n > i + m) || (i1 > j + k))) {
                    ModifyNumPopu.this.dismiss();
                }
                return true;
            }
        });
    }

    public void setOnClickOkBtn(OnClickOkBtn paramOnClickOkBtn) {
        this.onClickOkBtn = paramOnClickOkBtn;
    }

    public static abstract interface OnClickOkBtn {
        public abstract void OnClickOkBtn(String paramString);
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/popu/ModifyNumPopu.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */